package com.csj.mvvm.api

import com.csj.mvvm.api.retrofit.RetrofitClient

open class HttpUtil {

    companion object {
        @Volatile
        private var httpUtil: HttpUtil? = null

        fun getInstance() = httpUtil ?: synchronized(this) {
            httpUtil ?: HttpUtil().also { httpUtil = it }
        }
    }

//    companion object {
//        val instance: HttpUtil by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
//            HttpUtil() }
//    }

    private val mService by lazy { RetrofitClient.getInstance().create() }

    //可以直接在BaseViewModel中获取取ApiService对象，简化接口调用
    open fun getService(): ApiService {
        return mService
    }

    private val converter: Converter = GSonConverter.create()

    fun getConverter(): Converter {
        return converter
    }

}
